﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.ic;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.Check_hService
{
    public class Check_hService : ICheck_hService
    {
        private readonly ICheck_hRepository check_HRepository;
        private readonly IMapper mapper;

        public Check_hService(ICheck_hRepository check_HRepository,IMapper mapper)
        {
            this.check_HRepository = check_HRepository;
            this.mapper = mapper;
        }

        //添加盘点单
        public async Task<int> AddCheck_h(AddCheck_hDto addCheck_HDto)
        {
            Check_h check_H = mapper.Map<Check_h>(addCheck_HDto);
            return await check_HRepository.AddCheck_h(check_H);
        }

        //删除盘点单
        public async Task<int> DeleteCheck_h(int id)
        {
            return await check_HRepository.DeleteCheck_h(id);
        }

        //高级查询
        public async Task<FenYe<Check_h>> GetAdvancedCheck_h(FenYe<Check_h> fenYe, string? code, string? startdate, string? enddate, int? status, string? type, int? whid, string? createname, string? startcreatetime, string? endcreatetime, string? approvername, string? startapprovertime, string? endapprovertime, string? inuser)
        {
            return await check_HRepository.GetAdvancedCheck_h(fenYe, code, startdate, enddate, status, type, whid, createname, startcreatetime, endcreatetime, approvername, startapprovertime, endapprovertime, inuser);
        }

        public async Task<List<Check_h>> GetByPid(int procid)
        {
            return await check_HRepository.GetByPid(procid);
        }


        //分页查询
        public async Task<FenYe<Check_h>> GetCheck_h(FenYe<Check_h> fenYe, string? code, string? type, int? status, int? whid)
        {
            return await check_HRepository.GetCheck_h(fenYe,code,type,status,whid);
        }

        //根据id查询盘点单
        public async Task<Check_h> GetCheck_hById(int icid)
        {
            return await check_HRepository.GetCheck_hById(icid);
        }


        ////根据单号查询主键ID
        public async Task<int> Getid(string code)
        {
            return await check_HRepository.Getid(code);
        }


        //盘亏的单据
        public async Task<List<Check_h>> Getkui()
        {
            return await check_HRepository.Getkui();
        }

        public async Task<CheckTotals> Gettotal(
            string? proc_code, string? ic_code, string? ic_type, string? create_name,
            int? type_id, string? proc_primary_unit, int? wh_id, string? ic_user,
            string? createstartTime, string? createendTime,
            decimal? checkprofitNumMin, decimal? checkprofitNumMax,
            decimal? checklossesNumMin, decimal? checklossesNumMax,
            decimal? checkprofitTotalMin, decimal? checkprofitTotalMax,
            decimal? checklossesTotalMin, decimal? checklossesTotalMax,
            int[]? icStatusArray)
        {
            return await check_HRepository.Gettotal(
            proc_code, ic_code, ic_type, create_name,
            type_id, proc_primary_unit, wh_id, ic_user,
            createstartTime, createendTime,
            checkprofitNumMin, checkprofitNumMax,
            checklossesNumMin, checklossesNumMax,
            checkprofitTotalMin, checkprofitTotalMax,
            checklossesTotalMin, checklossesTotalMax,
            icStatusArray);
        }


        //盘盈的单据
        public async Task<List<Check_h>> Getying()
        {
            return await check_HRepository.Getying();
        }


        //修改盘点单
        public async Task<int> UpdateCheck_h(UpdateCheck_hDto updateCheck_HDto)
        {
            Check_h check_H=mapper.Map<Check_h>(updateCheck_HDto);
            return await check_HRepository.UpdateCheck_h(check_H);
        }


        //修改出入库状态
        public async Task<int> UpdateStatus(string name, int status, int ic_id)
        {
            return await check_HRepository.UpdateStatus(name, status, ic_id);
        }
    }
}
